{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "# QAACCOUNT 账户类"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "QA_Account() 是quantaxis的核心类, 其作用是一个可以使用规则兼容各种市场的账户类\n",
    "\n",
    "1.3.0以后, QA_Account需要由组合来进行创建(推荐)\n",
    "\n",
    "```python\n",
    "\n",
    "user = QA.QA_user(username ='quantaxis', password = 'quantaxis')\n",
    "portfotlio=user.new_portfolio('x1')\n",
    "account = portfolio.new_account(args)\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## 调用方式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " prortfolio with user_cookie  USER_QKoncetW  already exist!!\n"
     ]
    }
   ],
   "source": [
    "import QUANTAXIS as QA\n",
    "import uuid\n",
    "user = QA.QA_User(username ='quantaxis', password = 'quantaxis')\n",
    "portfolio=user.new_portfolio('x1')\n",
    "account = portfolio.new_account(account_cookie='test')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## 参数详解"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "# strategy_name=None,\n",
    "# user_cookie=None,\n",
    "# portfolio_cookie=None,\n",
    "# account_cookie=None,\n",
    "# market_type=MARKET_TYPE.STOCK_CN,\n",
    "# frequence=FREQUENCE.DAY,\n",
    "# broker=BROKER_TYPE.BACKETEST,\n",
    "# init_hold={},\n",
    "# init_cash=1000000,\n",
    "# commission_coeff=0.00025,\n",
    "# tax_coeff=0.001,\n",
    "# margin_level={},\n",
    "# allow_t0=False,\n",
    "# allow_sellopen=False,\n",
    "# allow_margin=False,\n",
    "# running_environment=RUNNING_ENVIRONMENT.BACKETEST"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## 基于规则实例化\n",
    "\n",
    "基于不同市场的不同规则, 我们可以实例化不同的账户类\n",
    "\n",
    "- 允许保证金交易:  allow_marigin = True\n",
    "\n",
    "- 允许买入后当日卖出: allow_t0 = True\n",
    "\n",
    "- 允许卖空开仓(裸卖空): allow_sellopen= True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "### 股票普通账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=False,allow_sellopen=False,market_type=QA.MARKET_TYPE.STOCK_CN)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 股票日内回转账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "stockt0_account =portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=False,allow_sellopen=False,market_type=QA.MARKET_TYPE.STOCK_CN,init_hold={'000002':500}, running_environment=QA.RUNNING_ENVIRONMENT.TZERO)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###   股票融资融券账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "rzrq_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=True,allow_sellopen=True,market_type=QA.MARKET_TYPE.STOCK_CN)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###  期货账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "future_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.FUTURE_CN)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "### 期权账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "option_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.OPTION_CN)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###  其他市场账户\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "xxx = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.CRYPTOCURRENCY)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## 账户的初始资金/初始仓位\n",
    "\n",
    "默认账户是无仓位, 默认现金 1000000 RMB\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cash': 1000000.0, 'hold': {}}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000000.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: amount, dtype: float64)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_hold"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###   在实例化的时候初始化仓位信息\n",
    "\n",
    "使用json/dict的格式初始化  \n",
    "\n",
    "```python\n",
    "# init_hold参数\n",
    "init_hold={code1:amount1,code2:amount2}\n",
    "```\n",
    "\n",
    "实例化完 会显示在 account.hold中\n",
    "\n",
    "[注意] 在t+1的账户中, 初始化仓位依然可以当日交易"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),init_hold={'000001':500}, allow_t0=False,allow_margin=False,allow_sellopen=False,running_environment=QA.MARKET_TYPE.STOCK_CN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cash': 1000000.0, 'hold': {'000001': 500}}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.sell_available"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "### 在实例化的时候初始现金信息\n",
    "\n",
    "```python\n",
    "# init_cash 参数\n",
    "init_cash= 200000\n",
    "```\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n",
      "QAACCOUNT: THIS ACCOUNT DOESNOT HAVE ANY TRADE\n"
     ]
    }
   ],
   "source": [
    "stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),init_cash= 200000,init_hold={'000002':500}, allow_t0=False,allow_margin=False,allow_sellopen=False,running_environment=QA.MARKET_TYPE.STOCK_CN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cash': 200000.0, 'hold': {'000002': 500}}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200000.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[200000.0]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200000.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "### 在已经实例化的账户中修改现金/ 重置现金操作\n",
    "\n",
    "此操作无法撤销\n",
    "\n",
    "- 现金记录全部消除\n",
    "- 账户的持仓不会消除\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "stock_account.reset_assets(init_cash=50000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cash': 50000.0, 'hold': {'000002': 500}}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.init_assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[50000.0]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50000.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash_available"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "##  买入/卖出操作\n",
    "\n",
    "有2种方式可以买入/卖出品种\n",
    "\n",
    "1. send_order 接口 + Order类调用receive_deal 接口\n",
    "2. receive_simpledeal 接口\n",
    "\n",
    "\n",
    "其中 \n",
    "- 1 是基于账户-发出订单- 订单成交回报的模式更新账户\n",
    "- 2 是直接修改账户的模式, 由用户自行确认和保证成交\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###  订单/更新账户的模式\n",
    "\n",
    "在此我们只演示订单/成交, 至于order.trade怎么成交, 则是市场类/broker类的问题, 在此不去演示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 生成订单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "order=stock_account.send_order(code='000001',amount=100,time='2019-01-19',\n",
    "                         amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,\n",
    "                         price=10,towards=QA.ORDER_DIRECTION.BUY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "future_order=future_account.send_order(code='RB1905',amount=100,time='2019-01-19',\n",
    "                         amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,\n",
    "                         price=3500,towards=QA.ORDER_DIRECTION.BUY_OPEN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account 93ba32ae-6544-4aa1-ad92-b41f76365bc6 market: future_cn>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 订单类 QA_Order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Order realorder_id Order_BM1rYubU datetime:2019-01-19 09:31:00 code:000001 amount:100.0 price:10.0 towards:1 btype:stock_cn order_id:Order_BM1rYubU account:0dd507d7-5d1a-4140-9d32-d549b0f42f95 status:queued >"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Order realorder_id Order_OAcNHXbT datetime:2019-01-19 09:31:00 code:RB1905 amount:100.0 price:3500.0 towards:2 btype:future_cn order_id:Order_OAcNHXbT account:93ba32ae-6544-4aa1-ad92-b41f76365bc6 status:queued >"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_order"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 订单交易(成交在Market/Broker中判断,此处只演示成交回报)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "order.trade(trade_price=10.1,trade_amount=100,trade_id='example_trade1',trade_time='2019-01-19 15:00:00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "future_order.trade(trade_price=3600,trade_amount=100,trade_id='example_trade2',trade_time='2019-01-19 21:00:00')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 账户成交表  QA_Account.history/QA_Account.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "      <th>direction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-19 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>10.1</td>\n",
       "      <td>100</td>\n",
       "      <td>48985.0</td>\n",
       "      <td>Order_BM1rYubU</td>\n",
       "      <td>Order_BM1rYubU</td>\n",
       "      <td>example_trade1</td>\n",
       "      <td>0dd507d7-5d1a-4140-9d32-d549b0f42f95</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code  price  amount     cash        order_id  \\\n",
       "0  2019-01-19 15:00:00  000001   10.1     100  48985.0  Order_BM1rYubU   \n",
       "\n",
       "     realorder_id        trade_id                        account_cookie  \\\n",
       "0  Order_BM1rYubU  example_trade1  0dd507d7-5d1a-4140-9d32-d549b0f42f95   \n",
       "\n",
       "   commission  tax message  frozen  direction  \n",
       "0         5.0  0.0    None       0          1  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "      <th>direction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-19 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3600.0</td>\n",
       "      <td>100</td>\n",
       "      <td>675640.0</td>\n",
       "      <td>Order_OAcNHXbT</td>\n",
       "      <td>Order_OAcNHXbT</td>\n",
       "      <td>example_trade2</td>\n",
       "      <td>93ba32ae-6544-4aa1-ad92-b41f76365bc6</td>\n",
       "      <td>360.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>None</td>\n",
       "      <td>324000.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code   price  amount      cash        order_id  \\\n",
       "0  2019-01-19 21:00:00  RB1905  3600.0     100  675640.0  Order_OAcNHXbT   \n",
       "\n",
       "     realorder_id        trade_id                        account_cookie  \\\n",
       "0  Order_OAcNHXbT  example_trade2  93ba32ae-6544-4aa1-ad92-b41f76365bc6   \n",
       "\n",
       "   commission  tax message    frozen  direction  \n",
       "0       360.0  0.0    None  324000.0          2  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.history_table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 账户现金表/ 期货账户还会冻结资金(保证金)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[50000.0, 48985.0]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1000000.0, 675640.0]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 3240.0, 'amount': 100, 'avg_price': 3600.0},\n",
       "  '-2': {'money': 0, 'amount': 0, 'avg_price': 0}}}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.frozen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 账户可用现金"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48985.0"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "675640.0"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.cash_available"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 账户持仓"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001    100\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "RB1905    100\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.hold"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "#### 账户可卖余额(股票T+1 因此可卖部分不增加/ 期货账户 t+0 因此可卖部分增加)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "RB1905    100\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.sell_available"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "###    直接操作账户模式\n",
    "\n",
    "该模式直接操作账户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "stock_account.receive_simpledeal(code='000004',order_id='model2',realorder_id='model2_real',trade_id='trade2',trade_amount=1000,trade_price=16,trade_time='2019-01-21',trade_towards=QA.ORDER_DIRECTION.BUY,message='model2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "      <th>direction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-19 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>10.1</td>\n",
       "      <td>100</td>\n",
       "      <td>48985.0</td>\n",
       "      <td>Order_BM1rYubU</td>\n",
       "      <td>Order_BM1rYubU</td>\n",
       "      <td>example_trade1</td>\n",
       "      <td>0dd507d7-5d1a-4140-9d32-d549b0f42f95</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-21</td>\n",
       "      <td>000004</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1000</td>\n",
       "      <td>32980.0</td>\n",
       "      <td>model2</td>\n",
       "      <td>model2_real</td>\n",
       "      <td>trade2</td>\n",
       "      <td>0dd507d7-5d1a-4140-9d32-d549b0f42f95</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>model2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code  price  amount     cash        order_id  \\\n",
       "0  2019-01-19 15:00:00  000001   10.1     100  48985.0  Order_BM1rYubU   \n",
       "1           2019-01-21  000004   16.0    1000  32980.0          model2   \n",
       "\n",
       "     realorder_id        trade_id                        account_cookie  \\\n",
       "0  Order_BM1rYubU  example_trade1  0dd507d7-5d1a-4140-9d32-d549b0f42f95   \n",
       "1     model2_real          trade2  0dd507d7-5d1a-4140-9d32-d549b0f42f95   \n",
       "\n",
       "   commission  tax message  frozen  direction  \n",
       "0         5.0  0.0    None       0          1  \n",
       "1         5.0  0.0  model2       0          1  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[50000.0, 48985.0, 32980.0]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "32980.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.cash_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001     100\n",
       "000002     500\n",
       "000004    1000\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.sell_available"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "##   结算\n",
    "\n",
    "主要是股票账户的可卖股数的结算\n",
    "\n",
    "目前期货账户不采用逐日盯市的结算方式(及无结算价/无当日盈亏)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "stock_account.settle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001     100\n",
       "000002     500\n",
       "000004    1000\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "future_account.settle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "##  关于账户存储和恢复"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## 动态字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account 93ba32ae-6544-4aa1-ad92-b41f76365bc6 market: future_cn>"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "      <th>direction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-19 21:00:00</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3600.0</td>\n",
       "      <td>100</td>\n",
       "      <td>675640.0</td>\n",
       "      <td>Order_OAcNHXbT</td>\n",
       "      <td>Order_OAcNHXbT</td>\n",
       "      <td>example_trade2</td>\n",
       "      <td>93ba32ae-6544-4aa1-ad92-b41f76365bc6</td>\n",
       "      <td>360.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>None</td>\n",
       "      <td>324000.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime    code   price  amount      cash        order_id  \\\n",
       "0  2019-01-19 21:00:00  RB1905  3600.0     100  675640.0  Order_OAcNHXbT   \n",
       "\n",
       "     realorder_id        trade_id                        account_cookie  \\\n",
       "0  Order_OAcNHXbT  example_trade2  93ba32ae-6544-4aa1-ad92-b41f76365bc6   \n",
       "\n",
       "   commission  tax message    frozen  direction  \n",
       "0       360.0  0.0    None  324000.0          2  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB1905': {'2': {'money': 3240.0, 'amount': 100, 'avg_price': 3600.0},\n",
       "  '-2': {'money': 0, 'amount': 0, 'avg_price': 0}}}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "675640.0"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.cash_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "RB1905    100\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "RB1905    100\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "future_account.hold_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account 0dd507d7-5d1a-4140-9d32-d549b0f42f95 market: stock_cn>"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: amount, dtype: float64)"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.hold_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.buy_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "ordert0=stockt0_account.send_order(code='000002',amount=100,time='2019-01-19',\n",
    "                         amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,\n",
    "                         price=10,towards=QA.ORDER_DIRECTION.BUY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    400\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.buy_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: amount, dtype: float64)"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.hold_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!receive deal\n"
     ]
    }
   ],
   "source": [
    "ordert0.trade(trade_price=10.1,trade_amount=100,trade_id='example_trade1',trade_time='2019-01-19 15:00:00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    100\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.hold_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    500\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.sell_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000002    400\n",
       "Name: amount, dtype: int64"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stockt0_account.buy_available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
